package com.technodo.gamedata;

import org.json.JSONException;
import org.json.JSONObject;

import com.technodo.enums.ItemStatus;
import com.technodo.utils.GlobalPreferences;

/**
 * Represents a particular product
 * 
 * @author Gaurav
 *
 */
public class Product {

	/**
	 * Unique Name of the Product
	 */
	private String name;
	/**
	 * Common Name of the Product (for display in UI)
	 */
	private String title;
	/**
	 * Quote related to the tech
	 */
	private String quote;
	/**
	 * Quoter related to the tech 
	 */
	private String quoter;
	/**
	 * IconPath of this icon
	 */
	private String iconPath;
	/**
	 * Full fledged image of the Tech
	 */
	private String imagePath;
	/**
	 * Name of Tech 1
	 */
	private String tech1name;
	/**
	 * Name of Tech 2
	 */
	private String tech2name;
	/**
	 * Level of Engg required
	 */
	private Integer engg;
	/**
	 * Level of Factory required
	 */
	private Integer factory;
	/**
	 * Increase in brand value due to this product
	 */
	private Integer brandValue;
	/**
	 * Increase in profit for the product
	 */
	private Integer profit;

	//////////////////////////////////////////////////////////////////
	// Elements which are dynamic
	/**
	 * Current Status of the item
	 */
	private ItemStatus status;
	/**
	 * Owner of the Item
	 */
	private PlayerBoard playerBoard;
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */


	/**
	 * Parses json and creates a new product object
	 * 
	 * @param jsonProduct json mapping of a particular product
	 */
	public Product(JSONObject jsonProduct) throws IllegalArgumentException, JSONException {

		// Parse the Json tech and convert to Java data structure
		name    = jsonProduct.optString("name");
		title   = jsonProduct.optString("title");
		quote	= jsonProduct.optString("quote", "Magenta and Purple are the same, atleast in RGB sense");
		quoter  = jsonProduct.optString("quoter", "Gaurav Roy");
		iconPath= jsonProduct.optString("icon", GlobalPreferences.defaultTechIcon);
		imagePath= jsonProduct.optString("image", GlobalPreferences.defaultTechIcon);
		tech1name = jsonProduct.optString("tech1");
		tech2name = jsonProduct.optString("tech2");
		factory = jsonProduct.optInt("factory");
		engg = jsonProduct.optInt("engg");
		brandValue = jsonProduct.optInt("bv");
		profit = jsonProduct.optInt("profit");

		// Initialise non Json variables
		setPlayerBoard(null);
		setStatus(ItemStatus.AVAILABLE);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Product [name=" + name + ", title=" + title + ", quote="
				+ quote + ", quoter=" + quoter + ", iconPath=" + iconPath
				+ ", imagePath=" + imagePath + ", tech1name=" + tech1name
				+ ", tech2name=" + tech2name + ", engg=" + engg + ", factory="
				+ factory + ", brandValue=" + brandValue + ", status=" + status
				+ "]";
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * @return the quote
	 */
	public String getQuote() {
		return quote;
	}

	/**
	 * @param quote the quote to set
	 */
	public void setQuote(String quote) {
		this.quote = quote;
	}

	/**
	 * @return the quoter
	 */
	public String getQuoter() {
		return quoter;
	}

	/**
	 * @param quoter the quoter to set
	 */
	public void setQuoter(String quoter) {
		this.quoter = quoter;
	}

	/**
	 * @return the iconPath
	 */
	public String getIconPath() {
		return iconPath;
	}

	/**
	 * @param iconPath the iconPath to set
	 */
	public void setIconPath(String iconPath) {
		this.iconPath = iconPath;
	}

	/**
	 * @return the imagePath
	 */
	public String getImagePath() {
		return imagePath;
	}

	/**
	 * @param imagePath the imagePath to set
	 */
	public void setImagePath(String imagePath) {
		this.imagePath = imagePath;
	}

	/**
	 * @return the tech1name
	 */
	public String getTech1name() {
		return tech1name;
	}

	/**
	 * @param tech1name the tech1name to set
	 */
	public void setTech1name(String tech1name) {
		this.tech1name = tech1name;
	}

	/**
	 * @return the tech2name
	 */
	public String getTech2name() {
		return tech2name;
	}

	/**
	 * @param tech2name the tech2name to set
	 */
	public void setTech2name(String tech2name) {
		this.tech2name = tech2name;
	}

	/**
	 * @return the engg
	 */
	public Integer getEngg() {
		return engg;
	}

	/**
	 * @param engg the engg to set
	 */
	public void setEngg(Integer engg) {
		this.engg = engg;
	}

	/**
	 * @return the factory
	 */
	public Integer getFactory() {
		return factory;
	}

	/**
	 * @param factory the factory to set
	 */
	public void setFactory(Integer factory) {
		this.factory = factory;
	}

	/**
	 * @return the status
	 */
	public ItemStatus getStatus() {
		return status;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(ItemStatus status) {
		this.status = status;
	}

	/**
	 * @return the playerBoard
	 */
	public PlayerBoard getPlayerBoard() {
		return playerBoard;
	}

	/**
	 * @param playerBoard the playerBoard to set
	 */
	public void setPlayerBoard(PlayerBoard playerBoard) {
		this.playerBoard = playerBoard;
	}

	/**
	 * @return the brandValue
	 */
	public Integer getBrandValue() {
		return brandValue;
	}

	/**
	 * @param brandValue the brandValue to set
	 */
	public void setBrandValue(Integer brandValue) {
		this.brandValue = brandValue;
	}

	/**
	 * @return the profit
	 */
	public Integer getProfit() {
		return profit;
	}

	/**
	 * @param profit the profit to set
	 */
	public void setProfit(Integer profit) {
		this.profit = profit;
	}


}
